package com.iplay.dahua.chapter2.strategy;

/**
 * 策略枚举
 * @author dangwu
 * @since 2021/9/3 1:03 下午
 */
public enum Calculator {
    /**
     * 加法运算
     */
    ADD("+"){
        @Override
        public int exec(int a, int b){
            return a + b;
        }
    },
    /**
     * 减法运算
     */
    SUB("-"){
        @Override
        public int exec(int a, int b){
            return a + b;
        }
    },
    /**
     * 减法运算
     */
    DIV("/"){
        @Override
        public int exec(int a, int b) {
            return 0;
        }
    },;

    String value;

    private Calculator(String value){
        this.value = value;
    }
    public String getValue(){
        return this.value;
    }

    /**
     * 声明一个抽象函数
     * @param a
     * @param b
     * @return
     */
    public abstract int exec(int a,int b);

    public static void main(String[] args) {
        int a = 1;
        int b = 2;
        int exec = Calculator.ADD.exec(a, b);
        System.out.println(exec+"     "+Calculator.ADD.getValue());
    }
}
